/**
 * Created by red on 2017/4/30.
 */
import parse from '@/utils/parse';
/**
 * 问题管理
 * @type {Object}
 */
export default [
  {
    name: '问题列表',
    method: 'questionList',
    excute: ({ data, fn, errFn } = {}) => {
      parse.query('question_banks', query => query.equalTo('chapter_id', data))
      .filter(x => x.type && x.type === 'result')
        .map(x => {
          return x.result.map(item => ({
            id: item.id,
            question_index: item.get('question_index'),
            question: item.get('question'),
            gold_coin: item.get('gold_coin'),
            silver_coin: item.get('silver_coin'),
            paragraph: item.get('paragraph'),
            answer_list: item.get('answer_list'),
          }));
        })
        .subscribe(fn, errFn);
    }
  },
  {
    name: '答案列表',
    method: 'answerList',
    excute: ({ data, fn, errFn } = {}) => {
      parse.query('answers', query => query.equalTo('question_id', data))
      .filter(x => x.type && x.type === 'result')
        .map(x => {
          return x.result.map(item => ({
            id: item.id,
            answer: item.get('answer'),
            answers_index: item.get('answers_index'),
            is_correct: item.get('is_correct'),
          }));
        })
        .subscribe(fn, errFn);
    }
  },
  {
    name: '答案结果',
    method: 'answerList',
    excute: ({ data, fn, errFn } = {}) => {
      parse.query('answers', query => query.equalTo('question_id', data))
      .filter(x => x.type && x.type === 'result')
        .map(x => {
          return x.result.map(item => ({
            id: item.id,
            answer: item.get('answer'),
            answers_index: item.get('answers_index'),
            is_correct: item.get('is_correct'),
          }));
        })
        .subscribe(fn, errFn);
    }
  },
];